﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Controls;
using System.Collections.ObjectModel;

namespace BallData
{
    public class FilterHistoryVS : IListenFilter
    {

        private MainUIControl uicontrol;

        public MainUIControl Uicontrol
        {
            get { return uicontrol; }
            set { uicontrol = value; }
        }
        public void OnListenFilter(Bet007_Match bi, Match_FilterItemBind fi, Bet007_AnalysisData ba)
        {
            
            #region "胜", "平", "负"
            if (fi.bFilter && (fi.szSelectFilterType == "胜" || fi.szSelectFilterType == "平" || fi.szSelectFilterType == "负") && Convert.ToInt32(fi.szFilter) > 0)
            {
                ObservableCollection<MatchListDataTemple> matchlist = OddsUntil.LeagueViewTemple[OddsUntil.Filter_MatchName] as ObservableCollection<MatchListDataTemple>;
                MatchItem ci = Gooooal_NetDataHelper.matchdataobj.getMatchItemByName(bi.t1CnName);

                if (ci == null)
                    return;
                int wincount = 0;
                int pingcount = 0;
                int lostcount = 0;
                foreach (Bet007_HistoryVS hisvs in ba.historylist)
                {
                    if (Convert.ToInt32(hisvs.hscore) > Convert.ToInt32(hisvs.vscore))
                    {
                        wincount++;
                    }
                    else if (Convert.ToInt32(hisvs.hscore) == Convert.ToInt32(hisvs.vscore))
                    {
                        pingcount++;
                    }
                    else
                    {
                        lostcount++;
                    }
                }
                if (wincount >= Convert.ToInt32(fi.szFilter) || pingcount >= Convert.ToInt32(fi.szFilter) || lostcount >= Convert.ToInt32(fi.szFilter))
                {
                    MatchListDataTemple matchlistdatatemple = OddsUntil.MathViewTemple[OddsUntil.GetMathViewKey(ci.mId, "1")] as MatchListDataTemple;
                    if (matchlistdatatemple != null && !matchlist.Contains(matchlistdatatemple))
                    {

                        Uicontrol.GetDispatcher().BeginInvoke((Action)(() =>
                        {
                            matchlist.Add(matchlistdatatemple);
                            Uicontrol.NotifyFilterMatchOk();
                        }));
                    }
                    else
                    {
                        Console.WriteLine("matchlistdatatemple null " + bi.t1CnName);
                    }
                }



            }
            #endregion
        }
    }
}
